package com.vates.proyectofinal.dao;

import java.util.List;


import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.vates.proyectofinal.entidades.Hotel;



@Repository
public class HotelDaoImpl  implements HotelDao{
	
	
	
	protected EntityManager entityManager;
	
	
	

	public EntityManager getEntityManager() {
		return entityManager;
	}
	
	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public List<Hotel> getHotel() {
		
		entityManager.persist(new Hotel());
		
		javax.persistence.Query query =  getEntityManager().createQuery("SELECT * FROM HOTEL");
		List<Hotel> resultList=  query.getResultList();
		return resultList;
		
	}

	
	@Transactional
	public Hotel getHotel(int idHotel) {

		return getEntityManager().find(Hotel.class, idHotel);
		
	}
	
	
	
	
}